package handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.CharsetUtil;

/**
 * @description:
 * @author: sali
 * @date: 2025/2/16 下午2:24.
 * @version: 1.0
 */
public class SocketMessageEncode extends MessageToByteEncoder {

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        ByteBuf byteBuf = (ByteBuf)msg;
        String msgStr = byteBuf.toString(0,byteBuf.readableBytes(), CharsetUtil.UTF_8);
        out.writeCharSequence(msgStr, CharsetUtil.UTF_8);
    }

}
